# -*- coding: utf-8 -*-

from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.time_sensor.time_after_04_30 import time_after_04_30
from datetime import timedelta

from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dim.dim_lmdm_sys_first_code import jms_dim__dim_lmdm_sys_first_code
from jms.dim.dim_lmdm_sys_second_code import jms_dim__dim_lmdm_sys_second_code
from jms.dim.dim_lmdm_sys_tail_code import jms_dim__dim_lmdm_sys_tail_code
from jms.dim.dim_lmdm_sys_tail_code_staff import jms_dim__dim_lmdm_sys_tail_code_staff
from jms.dim.dim_lmdm_sys_network import jms_dim__dim_lmdm_sys_network
from jms.dim.lmdm.dim_yl_sys_package_different_base import jms_dim__dim_yl_sys_package_different_base

jms_ai_dw__yl_check_threesegcode_sample = SparkSqlOperator(
    master='yarn',
    execution_timeout=timedelta(minutes=180),
    sql='jms/aigroup/ai_dw/yl_check_threesegcode_sample/execute.sql',
    task_id='jms_ai_dw__yl_check_threesegcode_sample',
    conn_id='spark_default',
    pool_slots=2,
    # depends_on_past=True,  # 如果任务依赖于前一天的同名任务，则将 depends_on_past 设为 True
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_ai_dw__yl_check_threesegcode_sample_{{ execution_date| date_add(1) | cst_ds }}',  # yarn 任务名称
    driver_memory='12G',
    driver_cores=4,
    yarn_queue='pyspark',
    executor_memory='16G',
    executor_cores=4,
    num_executors=60,
    depends_on_past=False,
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={'spark.core.connection.ack.wait.timeout': 300,
          'spark.locality.wait': 60,
          'spark.dynamicAllocation.maxExecutors': 70,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 40,
          'spark.dynamicAllocation.enabled': 'true',
          'spark.shuffle.service.enabled': 'true',  # NodeManager中一个长期运行的辅助服务，用于提升Shuffle计算性能
          'spark.executor.memoryOverhead': '2G',
          'spark.sql.shuffle.partitions': 1000,  # spark.sql.shuffle.partitions则是只对SparkSQL有效
          },

)

# 设置依赖
jms_ai_dw__yl_check_threesegcode_sample << [
jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,jms_dim__dim_lmdm_sys_first_code,jms_dim__dim_lmdm_sys_second_code,
jms_dim__dim_lmdm_sys_tail_code,jms_dim__dim_lmdm_sys_tail_code_staff,jms_dim__dim_lmdm_sys_network,
jms_dim__dim_yl_sys_package_different_base,
    time_after_04_30,]
